package com.bit.frige.recipe;

import java.util.ArrayList;

import com.bit.frige.MainActivity;
import com.bit.frige.R;
import com.bit.frige.DB.DBContactHelper;
import com.bit.frige.DB.MyAdapter2;
import com.bit.frige.R.layout;
import com.bit.frige.R.menu;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class Recipefoodlist extends Activity {
	private ListView RecipeListV;
	private RecipeAdapter Adapter;
	private ArrayList<RecipeListDTO> list = new ArrayList<RecipeListDTO>();
	private Button btn1;
		
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_recipefoodlist);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        Intent intent = getIntent();
        
        RecipeListV = (ListView) findViewById(R.id.recipeListView);

 /*
        //레시피 데이터
        RecipeListDTO recipe1 = new RecipeListDTO(2001,"닭볶음탕",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%8B%AD%EB%B3%B6%EC%9D%8C%ED%83%95");
        RecipeListDTO recipe2 = new RecipeListDTO(2002,"제육볶음",
        		"http://cook.miznet.daum.net/search/search.do?q=%EC%A0%9C%EC%9C%A1%EB%B3%B6%EC%9D%8C");
        RecipeListDTO recipe3 = new RecipeListDTO(2003,"갈비찜",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B0%88%EB%B9%84%EC%B0%9C");
        RecipeListDTO recipe4 = new RecipeListDTO(2004,"갈치조림",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B0%88%EC%B9%98%EC%A1%B0%EB%A6%BC");
        RecipeListDTO recipe5 = new RecipeListDTO(2005,"고갈비",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B3%A0%EA%B0%88%EB%B9%84");
        RecipeListDTO recipe6 = new RecipeListDTO(2006,"장어구이",
        		"http://cook.miznet.daum.net/search/search.do?q=%EC%9E%A5%EC%96%B4%EA%B5%AC%EC%9D%B4");
        RecipeListDTO recipe7 = new RecipeListDTO(2007,"꽃게탕",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%BD%83%EA%B2%8C%ED%83%95");
        RecipeListDTO recipe8 = new RecipeListDTO(2008,"깐쇼세우",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B9%90%EC%87%BC%EC%83%88%EC%9A%B0");
        RecipeListDTO recipe9 = new RecipeListDTO(2009,"조개탕",
        		"http://cook.miznet.daum.net/search/search.do?q=%EC%A1%B0%EA%B0%9C%ED%83%95");
        RecipeListDTO recipe10 = new RecipeListDTO(2010,"감자전",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B0%90%EC%9E%90%EC%A0%84");
        RecipeListDTO recipe11 = new RecipeListDTO(2011,"꽈리고추  멸치볶음",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%BD%88%EB%A6%AC%EA%B3%A0%EC%B6%94+%EB%A9%B8%EC%B9%98%EB%B3%B6%EC%9D%8C");
        RecipeListDTO recipe12 = new RecipeListDTO(2012,"갈릭파스타",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B0%88%EB%A6%AD%ED%8C%8C%EC%8A%A4%ED%83%80");
        RecipeListDTO recipe13 = new RecipeListDTO(2013,"버섯전골",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%B2%84%EC%84%AF%EC%A0%84%EA%B3%A8");
        RecipeListDTO recipe14 = new RecipeListDTO(2014,"오이냉국",
        		"http://cook.miznet.daum.net/search/search.do?q=%EC%98%A4%EC%9D%B4%EB%83%89%EA%B5%AD");
        RecipeListDTO recipe15 = new RecipeListDTO(2015,"단호박 치즈구이",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%8B%A8%ED%98%B8%EB%B0%95%EC%B9%98%EC%A6%88%EA%B5%AC%EC%9D%B4");
        RecipeListDTO recipe16 = new RecipeListDTO(2016,"레몬꿀차",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%A0%88%EB%AA%AC%EA%BF%80%EC%B0%A8");
        RecipeListDTO recipe17 = new RecipeListDTO(2017,"배꿀찜",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%B0%B0%EA%BF%80%EC%B0%9C");
        RecipeListDTO recipe18 = new RecipeListDTO(2018,"파인애플 볶음밥",
        		"http://cook.miznet.daum.net/search/search.do?q=%ED%8C%8C%EC%9D%B8%EC%95%A0%ED%94%8C%EB%B3%B6%EC%9D%8C%EB%B0%A5");
        RecipeListDTO recipe19 = new RecipeListDTO(2019,"마파두부",
        		"http://cook.miznet.daum.net/search/search.do?q=%EB%A7%88%ED%8C%8C%EB%91%90%EB%B6%80");
        RecipeListDTO recipe20 = new RecipeListDTO(2020,"콩나물 잡채",
        		"http://cook.miznet.daum.net/search/search.do?q=%EC%BD%A9%EB%82%98%EB%AC%BC%EC%9E%A1%EC%B1%84");
        RecipeListDTO recipe21 = new RecipeListDTO(2021,"견과류 조림",
        		"http://cook.miznet.daum.net/search/search.do?q=%EA%B2%AC%EA%B3%BC%EB%A5%98%EC%A1%B0%EB%A6%BC");

        
        list.add(recipe1);
        list.add(recipe2);
        list.add(recipe3);
        list.add(recipe4);
        list.add(recipe5);
        list.add(recipe6);
        list.add(recipe7);
        list.add(recipe8);
        list.add(recipe9);
        list.add(recipe10);
        list.add(recipe11);
        list.add(recipe12);
        list.add(recipe13);
        list.add(recipe14);
        list.add(recipe15);
        list.add(recipe16);
        list.add(recipe17);
        list.add(recipe18);
        list.add(recipe19);
        list.add(recipe20);
        list.add(recipe21);
*/
                //DB연결
        DBContactHelper db = new DBContactHelper(this);
       
        list = db.getRecipe();
        Adapter = new RecipeAdapter(this, list);
        RecipeListV.setAdapter(Adapter);    
        
        RecipeListV.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int posion,
                            long id) {
                    Intent intent = new Intent(getApplicationContext(),RecipeWebActivity.class);
                    intent.putExtra("url", ""+list.get(posion).getRecipeUrl());
                    startActivity(intent);                                                          
                    
            }
    });

        
   
        btn1 = (Button) findViewById(R.id.button1);
        //홈이벤트
        btn1.setOnClickListener(new OnClickListener() {
                
                public void onClick(View v) {
                        Intent intentHome = new Intent(getApplicationContext(),MainActivity.class);
                        intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        intentHome.putExtra("load", 1);
                        startActivity(intentHome);
        }
        });
        
}
		
		
		
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.recipefoodlist, menu);
		return true;
	}

}






